package exercise.jslide.jslide.view.ribbon;

import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class RibbonButton extends Button {
    private String iconName;

    public RibbonButton() {
        super();
        getStyleClass().add("ribbon-button");
    }

    public RibbonButton(String text) {
        super(text);
        getStyleClass().add("ribbon-button");
    }

    public RibbonButton(String text, String iconName) {
        super(text);
        this.iconName = iconName;
        getStyleClass().add("ribbon-button");
        //TODO
//        setupIcon();
    }

    private void setupIcon() {
        try {
            String iconPath = "/icons/" + iconName + ".png";
            Image icon = new Image(getClass().getResourceAsStream(iconPath));
            ImageView imageView = new ImageView(icon);
            imageView.setFitWidth(16);
            imageView.setFitHeight(16);
            setGraphic(imageView);
        } catch (Exception e) {
            // 如果图标加载失败，只显示文本
            System.err.println("无法加载图标: " + iconName);
        }
    }
}